<template>
	<view class="">
		<!-- 放大的客服 -->
		<movable-area v-show="showKf" class="kf-movable-area" :class="{'hidden-customer-btn':loadAnimation}">
			 <movable-view class="kf-movable-view" @change="moveBtn" direction="horizontal" out-of-bounds>
				<button class="customer-service-btn" type="default" show-message-card="true" open-type="contact">
					<image class="customer-service-icon" src="https://jxfwpt-p.oss-cn-beijing.aliyuncs.com/words/kf-icon.png"></image>
					<span class="customer-service-text">在线咨询</span>
				</button> 
			</movable-view>
		</movable-area>
		<!-- 缩小客服 -->
		<div class="small-kf-block" @click="showBigIcon()">
			<image class="small-service-icon" src="https://jxfwpt-p.oss-cn-beijing.aliyuncs.com/words/kf-small-icon.png"></image>
		</div>
	</view>
</template>

<script>
	export default {
		name:"CustomService",
		data() {
			return {
				showKf: false,
				loadAnimation: false
			};
		},
		methods: {
			moveBtn(e) {
			    if(e.detail.x > 3 && e.detail.source == 'touch-out-of-bounds') {
			      this.loadAnimation = true
			    }
			},
			showBigIcon() {
				this.showKf = true
				this.loadAnimation = false
			}
		}
	}
</script>

<style scoped lang="scss">
	.kf-movable-area {
		position: fixed;
		right: 0px;
		bottom: 300rpx;
		height: 100rpx;
		width: 110rpx;
		overflow: hidden;
		z-index: 9999;
	}
	.kf-movable-view {
		display: flex;
		align-items: center;
		justify-content: center;
		height: 100rpx;
		width: 110rpx;
		color: #fff;
	}
	.customer-service-btn {
		// position: fixed;
		// right: 0px;
		// bottom: 300rpx;
		width: 110rpx;
		height: 96rpx;
		background-color: #00C780;
		display: block;
		border-radius: 55rpx 0 0 55rpx;
		.customer-service-icon {
			width: 30rpx;
			height: 30rpx;
			position: absolute;
			top: 18rpx;
			right: 34rpx;
		}
		.customer-service-text {
			background: none;
			color: #fff;
			font-size: 10px;
			padding: 0;
			margin: 0;
			border: none;
			line-height: 28rpx;
			position: absolute;
			bottom: 16rpx;
			right: 10rpx;
			border-radius: 0;
		}
	}
	.customer-service-btn::after {
		border: none;
	}
	.hidden-customer-btn {
		animation:myfirst 1s;
		-webkit-animation:myfirst 1s; /* Safari and Chrome */
		-webkit-animation-fill-mode: forwards;
	}
	@keyframes myfirst
	{
		0%   {right: 0;}
		100% {right: -110px;}
	}
	
	@-webkit-keyframes myfirst /* Safari and Chrome */
	{
		0%	 {right: 0;}
		100% {right: -110px;}
	}
	
	.small-kf-block {
		z-index: 9998;
		width: 34rpx;
		height: 66rpx;
		position: fixed;
		right: 0;
		bottom: 316rpx;
		.small-service-icon {
			width: 100%;
			display: initial;
		}
	}
</style>
